package prepro;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;

import myLucene.Props;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.spell.LuceneDictionary;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

public class TestDic {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		Directory iDirectory = FSDirectory.open(new File(Props.readIndexPath));
		IndexSearcher searcher = new IndexSearcher(iDirectory, true);
		IndexReader iReader = searcher.getIndexReader();
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"/local/joofeit/termsToInt")));
		String line = "";
		QueryParser queryParser = new QueryParser(Version.LUCENE_30,
				Props.queryField, new StandardAnalyzer(Version.LUCENE_30));
		LuceneDictionary d = new LuceneDictionary(iReader, "lemma");
		// HashMap<String, Integer> termsToInt = new HashMap<String, Integer>();
		int counter = 0;
		Iterator<String> dIter = d.getWordsIterator();
		HashSet<String> dic = new HashSet<String>();
		while (dIter.hasNext()) {
			String word = dIter.next();
			//System.out.println("> "+word);
			// if (!TermFre.stopWordOrNot(stop, word)) {
			dic.add(word);
			counter++;
			// }

		}
		while ((line = br.readLine()) != null) {
			if (line.split(" ").length == 2) {
				Query query2 = queryParser.parse(line.split(" ")[0].trim());

				//System.out.println(line.split(" ")[1].trim());
				
				if (dic.contains(line.split(" ")[1].trim())) {
					//System.out.println(" hit " + line);
				} else {
					System.out.println("no Hit :" + line.split(" ")[1].trim());
				}
			} else {
				throw new Exception("not well formed");
			}
		}
	}

}
